<?php
//活动查询条件

namespace App\Repositories\Filter;

class ActivitiesFilter
{

    /**
     * 处理查询条件
     * @param $query
     * @return array[]
     */
    public static function handleQuery($query = []) {
        $where = [];
        $whereIn = [];
        if (!empty($query['id'])) {
            $where[] = ['id', $query['id']];
        }
        if (!empty($query['ids'])) {
            $whereIn[] = ['id', $query['ids']];
        }
        if (!empty($query['title_keyword'])) {
            $where[] = ['title', 'like', "%{$query['title_keyword']}%"];
        }
        if (!empty($query['location_keyword'])) {
            $where[] = ['location', 'like', "%{$query['location_keyword']}%"];
        }
        if (!empty($query['receive_date_start_gte'])) {
            $where[] = ['receive_date_start', '>=', $query['receive_date_start_gte']];
        }
        if (!empty($query['receive_date_start_lt'])) {
            $where[] = ['receive_date_start', '<', $query['receive_date_start_lt']];
        }
        if (!empty($query['receive_date_end_gte'])) {
            $where[] = ['receive_date_end', '>=', $query['receive_date_end_gte']];
        }
        if (!empty($query['receive_date_end_lt'])) {
            $where[] = ['receive_date_end', '<', $query['receive_date_end_lt']];
        }
        if (!empty($query['created_at_gte'])) {
            $where[] = ['created_at', '>=', $query['created_at_gte']];
        }
        if (!empty($query['created_at_lt'])) {
            $where[] = ['created_at', '<', $query['created_at_lt']];
        }
        if (!empty($query['status'])) {
            $where[] = ['status', $query['status']];
        }
        if (!empty($query['type'])) {
            $where[] = ['type', $query['type']];
        }

        return [
            'where' => $where,
            'whereIn' => $whereIn,

        ];
    }

}
